package com.homwee.tvap.common.srvfunc;

import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.net.Uri;
import android.os.Environment;
//zcj 2018-10-31import android.os.SystemProperties;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;

import com.homwee.factory.FactoryIniReadService;
import com.mediatek.twoworlds.factory.MtkTvFApiSystem;
import com.mediatek.twoworlds.factory.common.MtkTvFApiKeyManager;

import java.io.BufferedReader;
import java.io.FileReader;
import android.os.StatFs;
import android.text.format.Formatter;

import com.homwee.factory.R.string;
//zcj 2018-10-30 import com.changhong.android.tvapi.common.vo.ChOsType;
//zcj 2018-10-30 import com.changhong.android.tvapi.common.vo.ChOsType.CHEnumSoundSystem;
//zcj 2018-10-30 import com.changhong.android.tvapi.common.vo.PanelInfo;
//import com.changhong.dm.DeviceManager;
//import com.changhong.dm.MountPoint;
import com.homwee.factory.util.Contants;
import com.homwee.tvap.common.comSettingInterface.factoryPage1;
import com.homwee.tvap.common.comSettingInterface.factoryPage10;
import com.homwee.tvap.common.comSettingInterface.factoryPage2;
import com.homwee.tvap.common.comSettingInterface.factoryPage3;
import com.homwee.tvap.common.comSettingInterface.factoryPage4;
import com.homwee.tvap.common.comSettingInterface.factoryPage5;
import com.homwee.tvap.common.comSettingInterface.factoryPage6;
import com.homwee.tvap.common.comSettingInterface.factoryPage7;
import com.homwee.tvap.common.comSettingInterface.factoryPage8;
import com.homwee.tvap.common.comSettingInterface.factoryPage9;
import com.mediatek.twoworlds.factory.common.MtkTvFApiDisplayTypes;
import com.mediatek.twoworlds.factory.common.MtkTvFApiInputSourceTypes;
import com.mediatek.twoworlds.factory.common.MtkTvFApiDisplayTypes.ColorTempData;
import com.mediatek.twoworlds.factory.model.MtkTvFApiMiuSysSscInfo;
import com.mediatek.twoworlds.factory.MtkTvFApiInformation;
import com.mediatek.twoworlds.tv.MtkTvCI;
//import com.changhong.tvos.common.exception.ChannelNotFoundException;
//import com.changhong.tvos.common.exception.IllegalValueException;
//import com.changhong.tvos.model.ATVChannelInfo;
//import com.changhong.tvos.model.ChOsType;
//import com.changhong.tvos.model.PanelInfo;
//zcj 2018-10-30 import com.changhong.tvos.service.TvCommonManager;


public class FactorySetting {

	private static FactorySetting mfactorySetting = null;
	static Context mContext = null;
	static MtkTvCI mMtkTvCI= null;
	private static String showNoFunc = null;

	private factoryPage1 Page1;
	private factoryPage2 Page2;
	private factoryPage3 Page3;
	private factoryPage4 Page4;
	private factoryPage5 Page5;
	private factoryPage6 Page6;
	private factoryPage7 Page7;
	private factoryPage8 Page8;
	private factoryPage9 Page9;
	private factoryPage10 Page10;

	public static FactorySetting getInstance(Context context) {
		if (mfactorySetting == null) {
			mContext = context;
			mfactorySetting = new FactorySetting();
			mMtkTvCI=MtkTvCI.getInstance(0);
		}
		return mfactorySetting;
	}

	private FactorySetting() {
		Page1 = factoryPage1.getInstance(mContext);
		Page2 = factoryPage2.getInstance(mContext);
		Page3 = factoryPage3.getInstance(mContext);
		Page4 = factoryPage4.getInstance(mContext);
		Page5 = factoryPage5.getInstance(mContext);
		Page6 = factoryPage6.getInstance(mContext);
		Page7 = factoryPage7.getInstance(mContext);
		Page8 = factoryPage8.getInstance(mContext);
		Page9 = factoryPage9.getInstance(mContext);
		Page10 = factoryPage10.getInstance(mContext);

	}

	// DeviceManager mDeviceManager = null;
	public List<StorageVolume> deviceLabel = Collections.synchronizedList((new ArrayList<StorageVolume>()));
	StorageVolume[] storageLabel = null;

	public boolean findUsbDir() {
		deviceLabel.clear();
		StorageManager storageManager = (StorageManager) mContext
				.getApplicationContext().getSystemService(
						Context.STORAGE_SERVICE);
		storageLabel = storageManager.getVolumeList();
		Log.d("CHFactorySetting.findUsb", String.valueOf(storageLabel.length));
		for (int i = 0; i < storageLabel.length; i++) {
			StorageVolume mStorageVolume = storageLabel[i];
			Log.d("CHFactorySetting.findUsb", mStorageVolume.getPath());
			Log.d("CHFactorySetting.findUsb", mStorageVolume.getState());
			if (mStorageVolume.getState().equalsIgnoreCase(
					Environment.MEDIA_MOUNTED)) {
				Log.d("CHFactorySetting.findUsb", mStorageVolume.getPath());
				deviceLabel.add(mStorageVolume);
			}
		}
		StorageVolume mPoint = null;
		// mDeviceManager = DeviceManager.getInstance();
		// deviceLabel =mDeviceManager.getMountPointList();
		try {
			for (StorageVolume point : deviceLabel) {
				if (point.getPath().contains("/mnt/media_rw")) {
				} else {
					mPoint = point;
					break;
				}
			}
			if (mPoint != null) {
				deviceLabel.remove(mPoint);
			}
		} catch (Exception e) {
			Log.d("CHFactorySetting.findUsb","exception in findusb()");
			e.printStackTrace();
		}
		if (deviceLabel.size() <= storageLabel.length -1 && deviceLabel.size()>0) {
			Log.d("CHFactorySetting.findUsb","deviceLabel.size()="+deviceLabel.size());
			return true;
		} else {
			return false;
		}
	}

	/*
	 * public boolean findUsbDir(){ return false; }
	 */

	public String searchFile(String name) {
		File file = null;
		String fileName = null;
		for (StorageVolume point : deviceLabel) {
			file = new File(point.getPath());
			fileName = searchFile(name, file);
			if (fileName != null) {
				break;
			}
		}
		return fileName;
	}
	public static String getTotalRam(){
		String path = "/proc/meminfo";
		String ramMemorySize = null;
		int totalRam = 0 ;
		try{
			FileReader fileReader = new FileReader(path);
			BufferedReader br = new BufferedReader(fileReader, 4096);
			ramMemorySize = br.readLine().split("\\s+")[1];
			br.close();
		}catch (Exception e){
			e.printStackTrace();
		}
		if(ramMemorySize != null){
			totalRam = (int)Math.ceil((new Float(Float.parseFloat(ramMemorySize) / (1024 * 1024)).doubleValue()));
		}

		return totalRam + "GB";
	}
	public static String getTotalRom() {
		File dataDir = Environment.getDataDirectory();
		StatFs stat = new StatFs(dataDir.getPath());
		long blockSize = stat.getBlockSizeLong();
		long totalBlocks = stat.getBlockCountLong();
		long size = totalBlocks * blockSize;
		long GB = 1024 * 1024 * 1024;
		final long[] deviceRomMemoryMap = {2*GB, 4*GB, 8*GB, 16*GB, 32*GB, 64*GB, 128*GB, 256*GB, 512*GB, 1024*GB, 2048*GB};
		String[] displayRomSize = {"2GB","4GB","8GB","16GB","32GB","64GB","128GB","256GB","512GB","1024GB","2048GB"};
		int i;
		for(i = 0 ; i < deviceRomMemoryMap.length; i++) {
			if(size <= deviceRomMemoryMap[i]) {
				break;
			}
		}
		return displayRomSize[i];
	}


	public File getFile(String name) {
		File file = null;
		for (StorageVolume point : deviceLabel) {
			file = new File(point.getPath() + File.separator + name);
			if(file!=null && file.length()!=0) {
				if (file.exists()) {
					break;
				}
			}
		}
		return file;

	}

	// public File getDirectory(String name){
	// File file =null;
	// for(StorageVolume point:deviceLabel){
	// File Tempfile =new File(point.getPath()+File.separator+name);
	// if(Tempfile.exists()){
	// file=Tempfile;
	// break;
	// }
	// }
	// Log.d("www",file.getAbsolutePath());
	// return file;
	//
	// }
	//

	private String searchFile(String keyword, File filepath) {
		String fileName = null;
		//
		if (filepath.isDirectory()) {
			File[] files = filepath.listFiles();

			if (files.length > 0) {
				for (File file : files) {

					//
					try {
						if (file.getName().indexOf(keyword) > -1
								|| file.getName()
										.indexOf(keyword.toUpperCase()) > -1) {
							fileName = file.getName();
							break;
						}
					} catch (Exception e) {

					}

				}
			}
		}
		return fileName;
	}

	public void copyFile(String filePath1, String filePath2) {
		Page2.copyFileByPath(filePath1, filePath2);
	}

	public void copyFileSupport(File[] fileList,File desFile){
		Page2.copyFileSupport(fileList,desFile);
	}

	public String getSWVersion() {
		return Page1.getSWVersion();
	}

	public String getSWDate() {
		return Page1.getSWDate();
	}

	/*** zcj start ***/
	public boolean isHDCPKey1XExist() {
		return Page1.isHDCPKey1XExist();
	}

	public boolean isHDCPKey2XExist() {
		return Page1.isHDCPKey2XExist();
	}

	public boolean isDTVCIPlusKeyExist() {
		boolean CIStatus = true;
		if(Page1.isDTVCIPlusKeyExist()){
		if (getKeyStatusIniFileExist(Contants.KEYSTATUS_CI)) {
			String CIRet = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_CI);
			if (CIRet != null && !CIRet.equalsIgnoreCase("OK")) {
				int i = 0;
				int encryptRt = 0;
				boolean result = false;
				for (i = 0; i < 3; i++) {
					encryptRt=mMtkTvCI.updateCIKeyWithPathEx(Contants.KEY_PATH_CIPLUS,0);
					Log.d("mytest1", encryptRt+"");
					Log.d("mytest1", i+"");
					if (0 == encryptRt) {
							break;
						}
					}
				if (i >= 3) {
						CIStatus = false;
					} 
				// MtkTvFApiInformation.getInstance().setIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
				// Contants.KEYSTATUS_CI, encryptRt + "");
				Page2.setCIPlusKeyToIni("" + (encryptRt == 0 ? "OK" : "NG:" + encryptRt));
                  }
                }
				}
		return Page1.isDTVCIPlusKeyExist() && CIStatus;
	}

	public boolean isWidevineKeyExist() {
		return Page1.isWidevineKeyExist();
	}
	
	public boolean isCLIENTCAKeyExist() {
		return Page1.isCLIENTCAKeyExist();
	}

	public boolean isNETFLIXKeyExist() {
		return Page1.isNETFLIXKeyExist();
	}
	public boolean isESNIDExist() {
		return Page1.isESNIDExist();
	}

	public boolean isKeyMasterExist() {
		return Page1.isKeyMasterExist();
	}

	public boolean isDeviceIdExist() {
		boolean ret=false;
		String deviceStr=Page2.getDeviceID();
		ret=!deviceStr.equalsIgnoreCase("null")&&checkDeviceIdIsValid(deviceStr);
		return ret;
	}

	public boolean isMacExist() {
		boolean ret=false;
		String macStr=Page2.getMAC();
		ret=!macStr.equalsIgnoreCase("null")&&checkMacIsValid(macStr);
		return ret;
	}

	public boolean isPlayReadyKeyExist() {
		return Page1.isPlayReadyExist();
	}
	/*
	public boolean isPlayReadyKey25Exist() {
		return Page1.isPlayReady25Exist();
	}
	*/
	public boolean isHashKeyExist() {
		return Page1.isHashKeyExist();
	}

	public boolean isProjectIdExist() {
		return Page1.isProjectIdExist();
	}
	public boolean isCIKeyNeeded() {
		return Page1.isCIKeyNeeded();
	}
	public boolean isHdcp2xKeyNeeded() {
		return Page1.isHdcp2xKeyNeeded();
	}
	public boolean isESNKeyNeeded() {
		return Page1.isESNKeyNeeded();
	}
	public boolean isPlayReadyKey25Needed() {
		return Page1.isPlayReadyKey25Needed();
	}
	/*** zcj end ***/
	public int getEepromTypeSize() {
		return Page1.getEepromTypeSize();
	}

	public boolean GetWithDTV() {
		return Page1.GetWithDTV();
	}

	public String GetFirmwareTag() {
		return Page1.GetFirmwareTag();
	}

	/****************************/

	public int getProductNum() {
		return Page1.getProductNum();
	}

	public int getProductIndex() {
		return Page1.getProductIndex();
	}

	public int getPanelIndex() {
		return Page1.getPanelIndex();
	}

	public int getPanelNum() {
		return Page1.getPanelNum();
	}

	public String getPanelName() {
		return Page1.getPanelName();
	}

	public String getCurProductName() {
		return Page1.getProductName();
	}

	public String getCurProjectIndex() {
		return Page1.getProjectIndex();
	}

	public void selectProductWithName(String strProductName) {
		Page1.selectProductWithName(strProductName);
	}

	public void setProductIndex(int value) {
		Page1.setProductIndex(value);
	}

	/*
	 * //zcj 2018-10-30 public PanelInfo getPanelInfo(){ return
	 * Page1.getPanelInfo(); }
	 */

	public void selectPanelWithName(String strPanelName) {
		Page1.selectPanelWithName(strPanelName);
	}

	public void setPanelIndex(int value) {
		Page1.setPanelIndex(value);
	}

	public String getPQVersion() {
		return Page1.getPQVersion();
	}

	public String getAQVersion() {
		return Page1.getAQVersion();
	}

	public String getFPVersion() {
		return Page1.getFPVersion();
	}

	public String getDataIndex(){
		return Page1.getDataIndex();
	}

	public String getTvosVersion() {
		// TODO Auto-generated method stub
		return Page1.getTvosVersion();
	}

	public String getMDWVersion() {
		// TODO Auto-generated method stub
		return Page1.getMDWVersion();
	}

	public String getDataVersion() {
		// TODO Auto-generated method stub
		return Page1.getDataVersion();
	}

	public String getNetActive() {
		return Page1.getNetActive();
	}

	public int setProductManualNetAct() {
		return Page1.setProductManualNetAct();
	}

	public int setShopManualNetAct(String mInputStr) {
		return Page1.setShopManualNetAct(mInputStr);
	}
	
	public String getIrModel() {
		return Page1.getIrModel();
	}
	
	/************* Page 2 ***************/
	public void setNetDetect() {
		Page2.setNetDetect();
	}

	public String getMAC() {
		return Page2.getMAC();
	}

	public String getMACFromIni() {
		return Page2.getMACFromIni();
	}

	public boolean isLanConnected() {
		return Page2.isLanConnected();
	}

	public String getLightSensorValue() {
		return Page2.getLightSensorValue();
	}

	public String getDeviceID() {
		return Page2.getDeviceID();
	}
	
	public String getTvWorkTime() {
		return Page2.getTvWorkTime();
	}
	
	public void setTvWorkTime() {
		 Page2.setTvWorkTime();
	}

	public String getDeviceIDFormIni() {
		return Page2.getDeviceIDFormIni();
	}
	
	public int getPIDStatus() {
		return Page2.getPIDStatus();
	}

	public String getPID() {
		return Page2.getPID();
	}

	public void setPID(String valueStr) {
		Page2.setPID(valueStr);
	}

	public String getIPAdress() {
		return Page2.getIPAdress();
	}

	public boolean setMAC(String mac) {
		boolean ret = false;
		ret = Page2.setMAC(mac);
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_MAC)) { 
			ret = Page2.setMacToIni(mac);
		}
		 
		return ret;
	}

	public void setUSBUpdateMAC() {
		Page2.setUSBUpdateMAC();
	}

	public boolean setDeviceID(String deviceID) {
		boolean ret = false;
		if(checkDeviceIdIsValid(deviceID)){
			ret = Page2.setDeviceID(deviceID);
			if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_DEVICEID)) {
				ret = Page2.setDeviceIDToIni(deviceID);
				Page2.saveUpgradeKeyFileName("DEVICEID", deviceID);
			}
		}
		return ret;
	}

	public boolean setBackupDataToUSB(byte[] buffer, int length) {
		return Page2.setBackupDataToUSB(buffer, length);
	}

	public int getScreenCS() {
		return Page2.getScreenCS();
	}

	public void setScreenUpgrade() {
		Page2.setScreenUpgrade();
	}

	public void changeFileMode(int mode,String path){
		Page2.changeFileMode(mode,path);
	}

	public void customerUpdate(Context mContext){
		Page2.customerUpdate(mContext);
	}

	public void WriteProjectIDToEeprom(){
		Page2.WriteProjectIDToEeprom();
	}
	/************* ��г���� ***************/
	public void setATVDTVSearch() {
		Page3.setATVDTVSearch();
	}

	public void setATVDTVAllSearchMode() {
		Page3.setATVDTVAllSearchMode();
	}

	public void setDTVAllSearchMode() {
		Page3.setDTVAllSearchMode();
	}

	public void initATVChannelTable(boolean isChangHongChannel) {
		Page3.initATVChannelTable();
	}

	public int getRecordAll(){
		return Page3.getRecordAll();
	}

	public void setRecordAll(int isRecordAll){
		Page3.setRecordAll(isRecordAll);
	}

	/*
	 * //zcj 2018-10-30 public ChOsType.CHEnumColorSystem getColorMode() throws
	 * Exception{ return Page3.getColorMode(); }
	 */

	public void setColorMode(int colorMode) throws Exception {
		Page3.setColorMode(colorMode);
	}

	/*
	 * //zcj 2018-10-30 public ChOsType.CHEnumSoundSystem getAudioMode() throws
	 * Exception{ return Page3.getAudioMode(); }
	 */

	public void setAudioMode(int audioMode) throws Exception {
		Page3.setAudioMode(audioMode);
	}

	public int getMuteColerIndex() {
		return Page3.getMuteColerIndex();
	}

	public void setMuteColerIndex(int index) {
		Page3.setMuteColerIndex(index);
	}

	public void setMemcIndex(int memcIndex){
		Page7.setMemcIndex(memcIndex);
	}
	public int getMemcIndex(){
		return Page7.getMemcIndex();
	}
	public int resetMemc(){
		return Page7.resetMemc();
	}
	public String getAutoEnterFactory(){ return Page7.getAutoEnterFactory();}
	public void setAutoEnterFactory(String value) { Page7.setAutoEnterFactory(value);}
	/*************
	 *
	 * 
	 *
	 ***************/
	public int getVolume() {
		return Page4.getVolume();
	}

	public void setVolume(int value) {
		Page4.setVolume(value);
	}

	public int getBalance() {
		return Page4.getBalance();
	}

	public void setBalance(int value) {
		Page4.setBalance(value);
	}

	/*************PAGE 5***************/
	public int getSourceIndex() {
		return Page5.getSourceIndex();
	}
	public String[] getSourceList() {
		return Page5.getSourceList();
	}

	public void setSourceIndex(int value) {
		Page5.setSourceIndex(value);
	}

	public int getColorTempMode() {
		return Page5.getColorTempMode();
	}

	public void setColorTempMode(int value) {
		Page5.setColorTempMode(value);
	}

	public int getRGain() {
		return Page5.getRGain();
	}
	public ColorTempData getColorTempData(MtkTvFApiDisplayTypes.EnumColorTemperature enumColorTemperature) {
		return Page5.getColorTempData(enumColorTemperature);
	}

	public int getGGain() {
		return Page5.getGGain();
	}

	public int getBGain() {
		return Page5.getBGain();
	}

	public void setRGain(int value) {
		Page5.setRGain(value);
	}
	public void setWbGain(MtkTvFApiDisplayTypes.EnumColorTemperature eColorTemp,ColorTempData mColorTempData) {
		Page5.setWbGain(eColorTemp,mColorTempData);
	}

	public void setGGain(int value) {
		Page5.setGGain(value);
	}

	public void setBGain(int value) {
		Page5.setBGain(value);
	}
	public void setBGainOffset(int value) {
		Page5.setBGainOffset(value);
	}
	public void setGGainOffset(int value) {
		Page5.setGGainOffset(value);
	}
	public void setRGainOffset(int value) {
		Page5.setRGainOffset(value);
	}

	public int getPowerMode() {
		return Page5.getPowerMode();
	}

	public void setPowerMode(int powerMode) {
		Page5.setPowerMode(powerMode);
	}

	public int getNonStandardFlag() {
		return Page5.getNonStandardFlag();
	}

	public void setNonStandardFlag(int flag) {
		Page5.setNonStandardFlag(flag);
	}

	public int getDebugFlag() {
		return Page5.getDebugFlag();
	}

	public int getLRMirror() {
		return Page5.getLRMirror();
	}

	public int getUDMirror() {
		return Page5.getUDMirror();
	}

	public void setLRMirror(int value) {
		Page5.setLRMirror(value);
	}

	public void setUDMirror(int value) {
		Page5.setUDMirror(value);
	}

	public void setDebugFlag(int flag) {
		Page5.setDebugFlag(flag);
	}

	public void resetEEP() {
		Page5.resetEEP();
	}

	public int setClearNetActive(String mInputStr) {
		return Page5.setClearNetActive(mInputStr);
	}

	public void setClearApp() {
		Page5.setClearApp();
	}

	public void setAgainLand() {
		Page5.setAgainLand();
	}

	/**************** SSC ****************/
	public int getLVDSSSC() {
		return Page6.getLVDSSSC();
	}

	public void setLVDSSSC(int value) {
		Page6.setLVDSSSC(value);
	}

	public int getMEMSSC() {
		return Page6.getMEMSSC();
	}

	public void setMEMSSC(int value) {
		Page6.setMEMSSC(value);
	}

	public int getLVDSLEVEL() {
		return Page6.getLVDSLevel();
	}

	public void setLVDSLEVEL(int value) {
		Page6.setLVDSLevel(value);
	}

	/************* page 7***************/
	public void systemInit() {
		// initATVChannelTable(false);
		Page7.systemInit();
	}

	public void quickSystemInit(){
		Page7.showResetToast();
		Page7.quickSystemInit();
	}

	public boolean isResetStart(){
		return Page7.isIsResetStart();
	}
	public void systemClearApp(){
		Page7.systemClearApp();
	}

	public void resetAutoEnterFactoryIni(){
		Page7.resetAutoEnterFactoryIni();
	}

	public void systemInitForPresetClientChannel() {
		// initATVChannelTable(false);
		Page7.systemInitForPresetClientChannel();
	}
	public void factoryResetPowerMode(){
		Page7.factoryResetPowerMode();
	}

	/*************
	 *
	 * 
	 *
	 ***************/
	public int getBackLight() throws Exception {
		return Page8.getBackLight();
	}

	public void setBackLight(int value) throws Exception {
		Page8.setBackLight(value);
	}

	public void copyVideoFile(String oriPath,String des){
		Page8.copyVideoToData(oriPath,des);
	}

	public void playDemoVideo(String path,Context context){
		Page8.playDemoVideo(path,context);
	}

	public String getShowModePlay(){
		return Page1.getShowModePlay();
	}

	public void setShowModePlay(String val){
		Page1.setShowModePlay(val);
	}

	/************* ��Ч��� ***************/
	public void setEnergyEfficiency() {
		Page9.setEnergyEfficiency();
	}

	/**************** DTV ****************/
	public void setDTVCIplus() {
		Page10.setDTVCIplus();
	}

	public String getDTVMidVersion() {
		return Page10.getDTVMidVersion();
	}

	public String getCIState() {
		return Page10.getCIState();
	}

	public boolean IsDTVSource() {
		// TODO Auto-generated method stub
		return Page10.IsDTVSource();
	}

	public int getDVBCVideoPid() {
		// TODO Auto-generated method stub
		return Page10.getDVBCVideoPid();
	}

	public int getDVBCAudioPid() {
		// TODO Auto-generated method stub
		return Page10.getDVBCAudioPid();
	}

	public int getDVBCPcrPid() {
		// TODO Auto-generated method stub
		return Page10.getDVBCPcrPid();
	}

	public int getDVBCfastScanEnable() {
		// TODO Auto-generated method stub
		return Page10.getDVBCfastScanEnable();
	}

	public void setDVBCfastScanEnable(int value) {
		// TODO Auto-generated method stub
		Page10.setDVBCfastScanEnable(value);
	}

	public int getDvbsSIParserType() {
		// TODO Auto-generated method stub
		return Page10.getDvbsSIParserType();
	}

	public void setDvbsSIParserType(int value) {
		// TODO Auto-generated method stub
		Page10.setDvbsSIParserType(value);
	}

	public int getFreeViewLogo() {
		// TODO Auto-generated method stub
		return Page10.getFreeViewLogo();
	}

	public void setFreeViewLogo(int value) {
		// TODO Auto-generated method stub
		Page10.setFreeViewLogo(value);
	}

	public void setPerformanceMonitor(int value) {
		// TODO Auto-generated method stub
		Page10.setPerformanceMonitor(value);
	}

	public void setCIDebugLevel(int index, int value) {
		// TODO Auto-generated method stub
		Page10.setCIDebugLevel(index, value);
	}

	public int getProcPeroid() {
		// TODO Auto-generated method stub
		return Page9.getProcPeroid();
	}

	public void setProcPeroid(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setProcPeroid(index, value);
	}

	public int getLmax() {
		// TODO Auto-generated method stub
		return Page9.getLmax();
	}

	public void setLmax(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setLmax(index, value);
	}

	public int getLDarkSence() {
		// TODO Auto-generated method stub
		return Page9.getLDarkSence();
	}

	public void setLumaHistWeight(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setLumaHistWeight(index, value);
	}

	public int getSampleTimes() {
		// TODO Auto-generated method stub
		return Page9.getSampleTimes();
	}

	public void setSampleTimes(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setSampleTimes(index, value);
	}

	public int getLowPointApl() {
		// TODO Auto-generated method stub
		return Page9.getLowPointApl();
	}

	public void setLowPointApl(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setLowPointApl(index, value);
	}

	public int getHighPointApl() {
		// TODO Auto-generated method stub
		return Page9.getHighPointApl();
	}

	public void setHighPointApl(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setHighPointApl(index, value);
	}

	public int getLowPointPwm() {
		// TODO Auto-generated method stub
		return Page9.getLowPointPwm();
	}

	public void setLowPointPwm(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setLowPointPwm(index, value);
	}

	public int getHighPointPwm() {
		// TODO Auto-generated method stub
		return Page9.getHighPointPwm();
	}

	public void setHighPointPwm(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setHighPointPwm(index, value);
	}

	public int getBigStepDiff() {
		// TODO Auto-generated method stub
		return Page9.getBigStepDiff();
	}

	public void setBigStepDiff(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setBigStepDiff(index, value);
	}

	public int getMidStepDiff() {
		// TODO Auto-generated method stub
		return Page9.getMidStepDiff();
	}

	public void setMidStepDiff(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setMidStepDiff(index, value);
	}

	public int getSmallStepDiff() {
		// TODO Auto-generated method stub
		return Page9.getSmallStepDiff();
	}

	public void setSmallStepDiff(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setSmallStepDiff(index, value);
	}

	public int getBigStepVal() {
		// TODO Auto-generated method stub
		return Page9.getBigStepVal();
	}

	public void setBigStepVal(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setBigStepVal(index, value);
	}

	public int getMidStepVal() {
		// TODO Auto-generated method stub
		return Page9.getMidStepVal();
	}

	public void setMidStepVal(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setMidStepVal(index, value);
	}

	public int getSmallStepVal() {
		// TODO Auto-generated method stub
		return Page9.getSmallStepVal();
	}

	public void setSmallStepVal(int index, int value) {
		// TODO Auto-generated method stub
		Page9.setSmallStepVal(index, value);

	}

	public void setGammaCompensateMode(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setGammaCompensateMode(i, value);
	}

	public int getGammaCompensateMode() {
		// TODO Auto-generated method stub
		return Page9.getGammaCompensateMode();
	}

	public void setCutPointPwm(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setCutPointPwm(i, value);
	}

	public int getCutPointPwm() {
		// TODO Auto-generated method stub
		return Page9.getCutPointPwm();
	}

	public void setCutPointApl(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setCutPointApl(i, value);
	}

	public int getCutPointApl() {
		// TODO Auto-generated method stub
		return Page9.getCutPointApl();
	}

	public void initPage9Data() {
		Page9.initPage9Data();
	}

	public int getPQOnOff() {
		// TODO Auto-generated method stub
		return Page9.getPQOnOff();
	}

	public void setPQOnOff(int value) {
		// TODO Auto-generated method stub
		Page9.setPQOnOff(value);
	}

	public int getDarkEnhenceDownSpeed() {
		// TODO Auto-generated method stub
		return Page9.getDarkEnhenceDownSpeed();
	}

	public void setDarkEnhenceDownSpeed(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setDarkEnhenceDownSpeed(i, value);
	}

	public int getPresetMidPointApl() {
		// TODO Auto-generated method stub
		return Page9.getPresetMidPointApl();
	}

	public void setPresetMidPointApl(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setPresetMidPointApl(i, value);
	}

	public int getPresetMidPointPwm() {
		// TODO Auto-generated method stub
		return Page9.getPresetMidPointPwm();
	}

	public void setPresetMidPointPwm(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setPresetMidPointPwm(i, value);
	}

	public int getDCCEnable() {
		// TODO Auto-generated method stub
		return Page9.getDCCEnable();
	}

	public void setDCCEnable(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setDCCEnable(i, value);
	}

	public int getDCCZeroPonit() {
		// TODO Auto-generated method stub
		return Page9.getDCCZeroPonit();
	}

	public void setDCCZeroPonit(int i, int value) {
		// TODO Auto-generated method stub
		Page9.setDCCZeroPonit(i, value);
	}

	public String getVHFLow() {
		// TODO Auto-generated method stub
		return Page3.getVHFLow();
	}

	public String getVHFHigh() {
		// TODO Auto-generated method stub
		return Page3.getVHFHigh();
	}

	public String getUHFLow() {
		// TODO Auto-generated method stub
		return Page3.getUHFLow();
	}

	public String getUHFHigh() {
		// TODO Auto-generated method stub
		return Page3.getUHFHigh();
	}

	public String getRFFilterCheck() {
		// TODO Auto-generated method stub
		return Page3.getRFFilterCheck();
	}

	public void startCheckRFFilter() {
		// TODO Auto-generated method stub
		Page3.startCheckRFFilter();
	}

	public int getGammaIndex() {
		// TODO Auto-generated method stub
		return Page9.getGammaIndex();
	}

	public void setGammaIndex(int value) {
		// TODO Auto-generated method stub
		Page9.setGammaIndex(value);
	}

	public boolean isPDP() {
		// TODO Auto-generated method stub
		return Page9.isPDP();
	}

	public boolean updateCurrentPaneldata() {
		// TODO Auto-generated method stub
		return Page2.updateCurrentPaneldata();
	}

	public void reboot() {
		// TODO Auto-generated method stub
	}

	public int getProductType() {
		// TODO Auto-generated method stub
		return Page1.getProductType();
	}

	public boolean Update6M40bindata(byte[] bytes, int length) {
		// TODO Auto-generated method stub
		return Page2.Update6M40bindata(bytes, length);
	}

	public boolean SupportAtvNonStarndardAdjust() {
		// TODO Auto-generated method stub
		return Page3.SupportAtvNonStarndardAdjust();
	}

	public int GetAtvNonstdVif_Top() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVif_Top();
	}

	public void SetAtvNonstdVif_Top(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVif_Top(value);
	}

	public void SetAtvNonstdVd_AFEC_D9bit0(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVd_AFEC_D9bit0(value);
	}

	public int GetAtvNonstdVd_AFEC_D9bit0() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVd_AFEC_D9bit0();
	}

	public void SetAtvNonstdVd_AFEC_D8bit3210(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVd_AFEC_D8bit3210(value);
	}

	public int GetAtvNonstdVd_AFEC_D8bit3210() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVd_AFEC_D8bit3210();
	}

	public void SetAtvNonstdVd_AFEC_D5bit2(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVd_AFEC_D5bit2(value);
	}

	public int GetAtvNonstdVd_AFEC_D5bit2() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVd_AFEC_D5bit2();
	}

	public void SetAtvNonstdVd_AFEC_D4(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVd_AFEC_D4(value);
	}

	public int GetAtvNonstdVd_AFEC_D4() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVd_AFEC_D4();
	}

	public void SetAtvNonstdVif_ChinaDescramblerbox(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVif_ChinaDescramblerbox(value);
	}

	public int GetAtvNonstdVif_ChinaDescramblerbox() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVif_ChinaDescramblerbox();
	}

	public void setProductName(String selName) {
		// TODO Auto-generated method stub
		Page1.saveProductName(selName);
	}

	public void setPanelName(String selName) {
		// TODO Auto-generated method stub
		Page1.savePanelName(selName);
	}

	public String getTunerName() {
		// TODO Auto-generated method stub
		return Page3.getTunerName();
	}

	public void setTunerName(String selName) {
		// TODO Auto-generated method stub
		Page3.setTunerName(selName);
	}

	public int GetAtvNonstdVd_Hidev() {
		// TODO Auto-generated method stub
		return Page3.GetAtvNonstdVd_Hidev();
	}

	public void SetAtvNonstdVd_Hidev(int value) {
		// TODO Auto-generated method stub
		Page3.SetAtvNonstdVd_Hidev(value);

	}

	public int getLvdsSSCEnable() {
		// TODO Auto-generated method stub
		return Page6.getLvdsSSCEnable();
	}

	public void setLvdsSSCEnable(int value) {
		// TODO Auto-generated method stub
		Page6.setLvdsSSCEnable(value);
	}

	public int getLvdsSSCSpan() {
		// TODO Auto-generated method stub
		return Page6.getLvdsSSCSpan();
	}

	public void setLvdsSSCSpan(int value) {
		// TODO Auto-generated method stub
		Page6.setLvdsSSCSpan(value);
	}

	public int getLvdsSSCStep() {
		// TODO Auto-generated method stub
		return Page6.getLvdsSSCStep();
	}

	public void setLvdsSSCStep(int value) {
		// TODO Auto-generated method stub
		Page6.setLvdsSSCStep(value);
	}

	public int getMIUEnable(int index) {
		// TODO Auto-generated method stub
		return Page6.getMIUEnable(index);
	}
	public MtkTvFApiMiuSysSscInfo getMIUInfo(int index) {
		// TODO Auto-generated method stub
		return Page6.getMIUInfo(index);
	}

	public void setMIUEnable(int index, int value) {
		// TODO Auto-generated method stub
		Page6.setMIUEnable(index, value);
	}

	public int getMIUModulation(int index) {
		// TODO Auto-generated method stub
		return Page6.getMIUModulation(index);
	}

	public void setMIUModulation(int index, int value) {
		// TODO Auto-generated method stub
		Page6.setMIUModulation(index, value);
	}

	public int getMIUPercentage(int index) {
		// TODO Auto-generated method stub
		return Page6.getMIUPercentage(index);
	}

	public int getLvdsSwing() {
		// TODO Auto-generated method stub
		return Page6.getLvdsSWing();
	}

	public void setLvdsSwing(int value) {
		// TODO Auto-generated method stub
		Page6.setLvdsSWing(value);
	}

	public void setMIUPercentage(int index, int value) {
		// TODO Auto-generated method stub
		Page6.setMIUPercentage(index, value);
	}

	public void setUrsaLvdsSscEnable(boolean benable) {
		Page6.setUrsaLvdsSscEnable(benable);
	}

	public void setUrsaLvdsSscSpan(int value) {
		Page6.setUrsaLvdsSscSpan(value);
	}

	public void setUrsaLvdsSscStep(int value) {
		Page6.setUrsaLvdsSscStep(value);
	}

	public void setUrsaLvdsSscLevel(int value) {
		Page6.setUrsaLvdsSscLevel(value);
	}

	public boolean getUrsaLvdsSscEnable() {
		return Page6.getUrsaLvdsSscEnable();
	}

	public int getUrsaLvdsSscSpan() {
		return Page6.getUrsaLvdsSscSpan();
	}

	public int getUrsaLvdsSscStep() {
		return Page6.getUrsaLvdsSscStep();
	}

	public int getUrsaLvdsSscLevel() {
		return Page6.getUrsaLvdsSscLevel();
	}

	public String get6m40Version() {
		// TODO Auto-generated method stub
		return Page1.get6m40Version();
	}

	public int getHDMINonstdType() {
		// TODO Auto-generated method stub
		return Page5.getHDMINonstdType();
	}

	public void setHDMINonstdType(int value) {
		// TODO Auto-generated method stub
		Page5.setHDMINonstdType(value);
	}

	public String getPanelSize() {
		// TODO Auto-generated method stub
		return Page1.getPanelSize();
	}

	public int getRedGain() {
		// TODO Auto-generated method stub
		return Page9.getRedGain();
	}

	public void setRedGain(int value) {
		// TODO Auto-generated method stub
		Page9.setRedGain(value);
	}

	public int getRedOffset() {
		// TODO Auto-generated method stub
		return Page9.getRedOffset();
	}

	public void setRedOffset(int value) {
		// TODO Auto-generated method stub
		Page9.setRedOffset(value);
	}

	public int getGreenGain() {
		// TODO Auto-generated method stub
		return Page9.getGreenGain();
	}

	public void setGreenGain(int value) {
		// TODO Auto-generated method stub
		Page9.setGreenGain(value);
	}

	public int getGreenOffset() {
		// TODO Auto-generated method stub
		return Page9.getGreenOffset();
	}

	public void setGreenOffset(int value) {
		// TODO Auto-generated method stub
		Page9.setGreenOffset(value);
	}

	public int getBlueGain() {
		// TODO Auto-generated method stub
		return Page9.getBlueGain();
	}

	public void setBlueGain(int value) {
		// TODO Auto-generated method stub
		Page9.setBlueGain(value);
	}

	public int getBlueOffset() {
		// TODO Auto-generated method stub
		return Page9.getBlueOffset();
	}

	public void setBlueOffset(int value) {
		// TODO Auto-generated method stub
		Page9.setBlueOffset(value);
	}

	public int getAtvNonstdVif() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif();
	}

	public void setAtvNonstdVif(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif(value);
	}

	// MST6586 ADD
	public int getAtvNonstdVif_AgcRef() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_AgcRef();
	}

	public void setAtvNonstdVif_AgcRef(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_AgcRef(value);
	}
/*
	public int getAtvNonstdVif_CrKp() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_CrKp();
	}
*/
	public MtkTvFApiInputSourceTypes.StructVifParams getVifParams() {
		// TODO Auto-generated method stub
		return Page3.getVifParams();
	}
/*
	public void setAtvNonstdVif_CrKp(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_CrKp(value);
	}

	public int getAtvNonstdVif_CrKi() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_CrKi();
	}

	public void setAtvNonstdVif_CrKi(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_CrKi(value);
	}
*/
	public int getAtvNonstdVif_AsiaSignalOption() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_AsiaSignalOption();
	}

	public void setAtvNonstdVif_AsiaSignalOption(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_AsiaSignalOption(value);
	}

	public int getAtvNonstdVif_ClampGainOvNegative() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_ClampGainOvNegative();
	}

	public void setAtvNonstdVif_ClampGainOvNegative(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_ClampGainOvNegative(value);
	}

	public int getAtvNonstdVif_ChinaDescramblerBoxDelay() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_ChinaDescramblerBoxDelay();
	}

	public void setAtvNonstdVif_ChinaDescramblerBoxDelay(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_ChinaDescramblerBoxDelay(value);
	}

	public int getAtvNonstdVif_CrThreshold() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_CrThreshold();
	}

	public void setAtvNonstdVif_CrThreshold(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_CrThreshold(value);
	}

	public int getAtvNonstdVif_DelayReduce() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_DelayReduce();
	}

	public void setAtvNonstdVif_DelayReduce(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_DelayReduce(value);
	}

	public int getAtvNonstdVif_VifVersion() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVif_VifVersion();
	}

	public void setAtvNonstdVif_VifVersion(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVif_VifVersion(value);
	}

	// vd
	public int getAtvNonstdVD_AefcD4() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcD4();
	}

	public void setAtvNonstdVD_AefcD4(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcD4(value);
	}

	public int getAtvNonstdVD_AefcD5Bit2() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcD5Bit2();
	}

	public void setAtvNonstdVD_AefcD5Bit2(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcD5Bit2(value);
	}

	public int getAtvNonstdVD_AefcD8Bit3210() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcD8Bit3210();
	}

	public void setAtvNonstdVD_AefcD8Bit3210(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcD8Bit3210(value);
	}

	public int getAtvNonstdVD_AefcD9Bit0() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcD9Bit0();
	}

	public void setAtvNonstdVD_AefcD9Bit0(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcD9Bit0(value);
	}

	public int getAtvNonstdVD_AefcD7HighBound() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcD7HighBound();
	}

	public void setAtvNonstdVD_AefcD7HighBound(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcD7HighBound(value);
	}

	public int getAtvNonstdVD_AefcD7LowBound() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcD7LowBound();
	}

	public void setAtvNonstdVD_AefcD7LowBound(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcD7LowBound(value);
	}

	public int getAtvNonstdVD_AefcA0() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcA0();
	}

	public void setAtvNonstdVD_AefcA0(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcA0(value);
	}

	public int getAtvNonstdVD_AefcA1() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_AefcA1();
	}

	public void setAtvNonstdVD_AefcA1(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_AefcA1(value);
	}

	public int getAtvNonstdVD_Aefc66Bit76() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_Aefc66Bit76();
	}

	public void setAtvNonstdVD_Aefc66Bit76(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_Aefc66Bit76(value);
	}

	public int getAtvNonstdVD_Aefc6EBit7654() {
		// TODO Auto-generated method stub
		return Page3.getAtvNonstdVD_Aefc6EBit7654();
	}

	public void setAtvNonstdVD_Aefc6EBit7654(int value) {
		// TODO Auto-generated method stub
		Page3.setAtvNonstdVD_Aefc6EBit7654(value);
	}

	public int getAgingModel() {
		// TODO Auto-generated method stub
		return Page5.getAgingModel();
	}

	public int getPVRRecordAll() {
		// TODO Auto-generated method stub
		return Page5.getPVRRecordAll();
	}

	public int getKeyUpgradeForce() {
		// TODO Auto-generated method stub
                int force = Page5.getKeyUpgradeForce();
                Log.d("zcj","getKeyUpgradeForce force "+force); 
                if(force == 0){
                String filename = searchFile(Contants.KEY_STRING_FORCE_UPGRADE_KEYS);
                if(filename != null){
                     force = 1;
                }
                Log.d("zcj","getKeyUpgradeForce getfile force "+force); 
                }

		return force;
	}

	public int getRemoteChannelPreset() {
		// TODO Auto-generated method stub
		int exist = -1;
		String filename = searchFile(Contants.REMOTE_CHANNEL_PRESET);
		if (filename != null) {
			exist = 0;
			Log.d("zcj", "RemoteChannelPreset getfile exist " + exist);
		}
		return exist;
	}

	public boolean isForcePID(){
		boolean forcePid=false;
		String filename = searchFile(Contants.FACTORY_FORCE_PROJECT_ID);
		if(filename != null){
			forcePid=true;
			Log.d("zcj","force pid update");
		}
		return forcePid;
	}

	public int getHashKeyUpgradeForce() {
		// TODO Auto-generated method stub
		int exist = -1;
		String filename = searchFile(Contants.HASHKEY_UPGRADE_FORCE);
		if (filename != null) {
			exist = 0;
			Log.d("zcj", "hashKeyUpgradeForce getfile exist " + exist);
		}
		return exist;
	}
	
	public int getIsFirstPowerON() {
		// TODO Auto-generated method stub
		return Page5.getIsFirstPowerON();
	}

	public int getSameService() {
		// TODO Auto-generated method stub
		return Page5.getSameService();
	}

	public void setAgingModel(int value) {
		// TODO Auto-generated method stub
		Page5.setAgingModel(value);
	}

	public void setPVRRecordAll(int value) {
		// TODO Auto-generated method stub
		Page5.setPVRRecordAll(value);
	}

	public void setKeyUpgradeForce(int value) {
		// TODO Auto-generated method stub
		Page5.setKeyUpgradeForce(value);
	}
	public void setFirstPowerON(int value) {
		// TODO Auto-generated method stub
		Page5.setFirstPowerON(value);
	}

	public void setSameService(int value) {
		// TODO Auto-generated method stub
		Page5.setSameService(value);
	}

	public int getUartOnOff() {
		// TODO Auto-generated method stub
		return Page5.getUartOnOff();
	}
	public int getNetworkAdb() {
		// TODO Auto-generated method stub
		return Page5.getNetworkAdb();
	}

	public void setUartOnOff(int value) {
		// TODO Auto-generated method stub
		Page5.setUartOnOff(value);
	}
	public void setNetworkAdb(int value) {
		// TODO Auto-generated method stub
		Page5.setNetworkAdb(value);
	}

	public int getWatchDogMode() {
		// TODO Auto-generated method stub
		return Page5.getWatchDogMode();
	}

	public void setWatchDogMode(int value) {
		// TODO Auto-generated method stub
		Page5.setWatchDogMode(value);
	}

	public int getWhiteBalance() {
		// TODO Auto-generated method stub
		return Page5.getWhiteBalance();
	}

	public void setWhiteBalance(int value) {
		// TODO Auto-generated method stub
		Page5.setWhiteBalance(value);
	}

	public int getFunctionPresetByIndex(byte index) {
		// TODO Auto-generated method stub
		return Page5.getFunctionPresetByIndex(index);
	}

	public void setFunctionPresetByIndex(byte index, int value) {
		// TODO Auto-generated method stub
		Page5.setFunctionPresetByIndex(index, value);
	}

	public void setFirstPowerPanelFlag(int value) {
		// TODO Auto-generated method stub
		Page5.setFirstPowerPanelFlag(value);
	}

	public int getWIFIOnOff() {
		// TODO Auto-generated method stub
		// int temp = 1;
		// temp=readFactoryMenuItemData("WOL_SWITCH");
		// return (temp==-1)?1:temp;
		return Page5.getWIFIOnOff();
	}

	public void setWIFIOnOff(int value) {
		// TODO Auto-generated method stub
		// saveFactoryMenuItemData("WOL_SWITCH",value);
		Page5.setWIFIOnOff(value);
	}

	public int getWOWOnOff() {
		// TODO Auto-generated method stub
		return Page5.getWOWOnOff();
	}

	public void setWOWOnOff(int value) {
		// TODO Auto-generated method stub
		Page5.setWOWOnOff(value);
	}

	public boolean EnableUartDebug() {
		// TODO Auto-generated method stub
		return Page5.EnableUartDebug();
	}

	public void cleanApp(boolean isShutDown) {
		// TODO Auto-generated method stub
		Page7.cleanApp(isShutDown);
	}

	public String getBootVersion() {
		// TODO Auto-generated method stub
		return Page1.getBootVersion();
	}

	public boolean setHdcpKey2x(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (checkFileFormat(src)) {
			ret = Page2.setHdcpKey2x(src);
		}
		if (ret) {
			File tempFile = getFile(src);
			Page2.saveUpgradeKeyFileName("HDCPKEY2", tempFile.getName());
			ret = deleteFileByPath(src);
			if (!ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HDCPKEY2)) {
				Page2.setHdcpKey2xToIni("NG:removeFile " + ret);
			}

		}
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HDCPKEY2)) {
			ret = Page2.setHdcpKey2xToIni("OK");
		}
		return ret;
	}

	public boolean setHdcpKey1x(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (checkFileFormat(src)) {
			ret = Page2.setHdcpKey1x(src);
		}
		if (ret) {
			File tempFile = getFile(src);
			Page2.saveUpgradeKeyFileName("HDCPKEY14", tempFile.getName());
			ret = deleteFileByPath(src);
			if (!ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HDCPKEY14)) {
				Page2.setHdcpKey2xToIni("NG:removeFile " + ret);
			}
		}
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HDCPKEY14)) {
			ret = Page2.setHdcpKey1xToIni("OK");
		}
		return ret;
	}

	public boolean setPlayReadyKey_1(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		ret = Page2.setPlayReadyKey_1(src);
		if (ret) {
			File tempFile = getFile(src);
			Page2.saveUpgradeKeyFileName("PLAYREADY_1", tempFile.getName());
		}
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_PLAYREADY_1)) {
			ret = Page2.setPlayReadyKey_1ToIni("OK");
		}
		return ret;
	}
	/*
	public boolean setPlayReadyKey25_1(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		ret = Page2.setPlayReadyKey25_1(src);
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_PLAYREADY25_1)) {
			File tempFile = getFile(src);
			Page2.saveUpgradeKeyFileName("PLAYREADY25_1", tempFile.getName());
			ret = Page2.setPlayReadyKey25_1ToIni("OK");
		}
		return ret;
	}
	*/
	public boolean setCLIENTCAKey(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		File mFileDir = new File(src);
		if (mFileDir.isDirectory()) {
			if (mFileDir.listFiles().length > 1) {
				String md5Txt = null;
				String fileMD5 = null;
				for (int i = 0; i < mFileDir.listFiles().length; i++) {
					File mfile = mFileDir.listFiles()[i];
					if (mfile.getAbsolutePath().contains(Contants.MD5INI_STRING)) {
						int fileLenght = (int) mfile.length();
						md5Txt = MtkTvFApiSystem.getInstance().readFile(mfile.getAbsolutePath(), fileLenght, 0);
						Log.d("zcj", md5Txt);
					} else {
						int fileLength = (int) mfile.length();
						fileMD5 = getMD5(mfile.getAbsolutePath(), fileLength);
						Log.d("zcj", fileMD5);
						src = mfile.getAbsolutePath();
					}
				}

				if (md5Txt != null) {
					if (md5Txt.equals(fileMD5)) {
						ret = Page2.setCLIENTCAKey(src);
						if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_CAKEY)) {
							if (ret) {
								File tempFile = getFile(src);
								Page2.saveUpgradeKeyFileName("CAKEY", tempFile.getName());
								ret = Page2.setCLIENTCAKeyToIni("OK");
							}
						}
						return ret;
					} else {
						if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_CAKEY)) {
							Page2.setCLIENTCAKeyToIni("NG:MD5 fails");
						}
					}
				} else {
					if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_CAKEY)) {
						Page2.setCLIENTCAKeyToIni("NG:getMD5 fails");
					}
					return ret;
				}
			}

		}
		// ret = Page2.setCLIENTCAKey(src);
		return ret;
	}
	public boolean setHashKey(String src) {
		// TODO Auto-generated method stub
		File mFileDir = new File(src);
		boolean ret = false;
		String str = mFileDir.listFiles().length + "";
		if (mFileDir.isDirectory()) {
			if (mFileDir.listFiles().length > 1) {
				String md5Txt = null;
				String fileMD5 = null;
				for (int i = 0; i < mFileDir.listFiles().length; i++) {
					File file = mFileDir.listFiles()[i];
					if (file.getAbsolutePath().contains(Contants.MD5INI_STRING)) {
						int fileLenght = (int) file.length();
						md5Txt = MtkTvFApiSystem.getInstance().readFile(file.getAbsolutePath(), fileLenght, 0);
						Log.d("zcj", md5Txt);
					} else {
						int fileLength = (int) file.length();
						fileMD5 = getMD5(file.getAbsolutePath(), fileLength);
						Log.d("zcj", fileMD5);
						src = file.getAbsolutePath();
					}
				}
				if (md5Txt != null) {
					if (md5Txt.equalsIgnoreCase(fileMD5)) {
						ret = Page2.setHashKey(src);
						if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HASHKEY)) {
							if (ret) {
								File tempFile = getFile(src);
								Page2.saveUpgradeKeyFileName("HASHKEY", tempFile.getName());
								ret = Page2.setHashKeyToIni("OK");
							} else {
								Page2.setHashKeyToIni("NG:copyFile " + ret);
							}
						}
						return ret;
					} else {
						if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HASHKEY)) {
							Page2.setHashKeyToIni("NG:MD5 fails");
						}
					}
				} else {
					if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_HASHKEY)) {
						Page2.setHashKeyToIni("NG:getMD5 fails");
					}
					return ret;
				}
			} else {
				// filelist.length<=1
				return false;
			}
		}
		return ret;
	}
	public boolean setProjectId(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		ret=Page2.setProjectId(src);
		return ret;
	}


	public boolean setPlayReadyKey_2(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		ret = Page2.setPlayReadyKey_2(src);
		if (ret) {
			File tempFile = getFile(src);
			Page2.saveUpgradeKeyFileName("PLAYREADY_2", tempFile.getName());
		}
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_PLAYREADY_2)) {
			ret = Page2.setPlayReadyKey_2ToIni("OK");
		}
		return ret;
	}
	/*
	public boolean setPlayReadyKey25_2(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		ret = Page2.setPlayReadyKey25_2(src);
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_PLAYREADY25_2)) {
			File tempFile = getFile(src);
			Page2.saveUpgradeKeyFileName("PLAYREADY25_2", tempFile.getName());
			ret = Page2.setPlayReadyKey25_2ToIni("OK");
		}
		return ret;
	}
*/

	public boolean setPlayReadyKeyToIni(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_PLAYREADY)) {
			ret = Page2.setPlayReadyKeyToIni(src);
		}else {
			ret = true;
		}
		return ret;
	}
/*
	public boolean setPlayReadyKey25ToIni(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_PLAYREADY25)) {
			ret = Page2.setPlayReadyKey25ToIni(src);
		}else {
			ret = true;
		}
		return ret;
	}
*/	
	public boolean setNetflixKey(String src) {
		// TODO Auto-generated method stub
		boolean ret = false,ret2 = false;
		File mFileDir=new File(src);
		if(mFileDir.isDirectory()){
			if(mFileDir.listFiles().length < 2){
				deleteDirByPath(src);
				src=src.substring(0,src.lastIndexOf("/")+1);
				File srcFile=new File(src);
				File updatefile = srcFile.listFiles()[0];
				return setNetflixKey(updatefile.getAbsolutePath());
			}
			//ret = Page2.setNetflixKey(src);
			for (int i = 0; i < mFileDir
					.listFiles().length; i++) {
				File file = mFileDir
						.listFiles()[i];
				//Log.d("Arthur1",file.getAbsolutePath());
				if (file.getAbsolutePath()
						.contains(
								Contants.KEY_STRING_NETFLIX_2)) {
					//Log.d("Arthur11",file.getAbsolutePath());
					ret = Page2.setNetflixKey(file.getAbsolutePath());
				} else if (file
						.getAbsolutePath()
						.contains(
								Contants.KEY_STRING_NETFLIX_1)) {
					//Log.d("Arthur12",file.getAbsolutePath());
					ret2 =Page2.setNetflixESNKey(file.getAbsolutePath());
				} else {
					continue;
				}
			}
		} else {
			return false;
		}
		if (ret && ret2) {
			Page2.saveUpgradeKeyFileName("NETFLIX", src);
			boolean rmRt = deleteDirByPath(src);
			if (rmRt) {
				if(Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_NETFLIX)){
					ret = Page2.setNetflixKeyToIni("OK");
				}
				if(Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_NETFLIX_ESN_KEY)){
					ret2 = Page2.setNetflixESNKeyToIni("OK");
				}
			} else {
				Page2.setNetflixKeyToIni("NG:removeFile " + rmRt);
			}
		}
		return ret && ret2;
	}

	public boolean setKeyMaster(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (checkFileFormat(src)) {
			ret = Page2.setKeyMaster(src);
			if (ret) {
				File tempFile = getFile(src);
				Page2.saveUpgradeKeyFileName("KEYMASTER", tempFile.getName());
				ret = deleteFileByPath(src);
				if (!ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_KEYMASTER)) {
					Page2.setKeyMasterToIni("NG:removeFile " + ret);
				}
			}
		}

		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_KEYMASTER)) {
			ret = Page2.setKeyMasterToIni("OK");
		}
		return ret;
	}

	public boolean setWidevineKey(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (checkFileFormat(src)) {
			ret = Page2.setWidevineKey(src);
			if (ret) {
				File tempFile = getFile(src);
				Page2.saveUpgradeKeyFileName("WIDEVINE", tempFile.getName());
				ret = deleteFileByPath(src);
				if (!ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_WIDEVINE)) {
					Page2.setWidevineKeyToIni("NG:removeFile " + ret);
				}
			}
		}
		if (ret && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_WIDEVINE)) {
			ret = Page2.setWidevineKeyToIni("OK");
		}
		return ret;
	}

	public boolean setCIPlusKey(String src) {
		// TODO Auto-generated method stub
		boolean ret = false;
		if (checkFileFormatCIkey(src)) {
			ret = Page2.setCIPlusKey(src);
			if (ret) {
				File tempFile = getFile(src);
				Page2.saveUpgradeKeyFileName("CI", tempFile.getName());
				boolean rmRet = deleteFileByPath(src);
				if (rmRet) {
					if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_CI)) {
						ret = Page2.setCIPlusKeyToIni("OK");
					}
				} else {
					if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_CI)) {
						ret = Page2.setCIPlusKeyToIni("NG:removeFile " + rmRet);
					}
				}
			}
		}
	//	if (ret && Page2.isKeyStatusIniFileExist()) {
	//		ret = Page2.setCIPlusKeyToIni("OK");
	//	}
		return ret;
	}
	
	public boolean getKeyStatusIniFileExist(String key) {
		// TODO Auto-generated method stub
		return Page2.isKeyStatusIniFileExist(key);
	}
	
	public boolean getKeyStatusIniFileExist() {
		// TODO Auto-generated method stub
		return Page2.isKeyStatusIniFileExist();
	}
	
	public boolean getUpgradeKeyFileIniExist(){
		return Page2.isUpgradeKeyFileExist();
	}

	public void getWhiteBalanceData_Standard(byte[] key) {
		// TODO Auto-generated method stub
		Page2.getWhiteBalanceData_Standard(key);
	}

	public void getWhiteBalanceData_Warm(byte[] key) {
		// TODO Auto-generated method stub
		Page2.getWhiteBalanceData_Warm(key);
	}

	public void getWhiteBalanceData_Cool(byte[] key) {
		// TODO Auto-generated method stub
		Page2.getWhiteBalanceData_Cool(key);
	}

	public boolean updateDigitalAmpdata() {
		return Page4.updateDigitalAmpdata();
	}

	public int readFactoryMenuItemData(String name) {
		int value = -1;
		try {
			Cursor cursor = mContext.getContentResolver().query(
					Uri.parse("content://com.changhong.factory/factorydata"),
					null, null, null, null);
			if (cursor == null) {
				ContentValues vals = new ContentValues();
				vals.put(name, 1);
				mContext.getContentResolver()
						.insert(Uri
								.parse("content://com.changhong.factory/factorydata"),
								vals);
				return value;
			}
			if (cursor.moveToFirst()) {
				value = (int) cursor.getInt(cursor.getColumnIndex(name));

			}

			cursor.close();
		} catch (Exception e) {
			Log.v("Factory", "readFactoryMenuItemData Exception");

		}
		return value;
	}

	public void saveFactoryMenuItemData(String name, int value) {
		long ret = -1;
		ContentValues vals = new ContentValues();
		vals.put(name, value);

		try {
			ret = mContext.getContentResolver().update(
					Uri.parse("content://com.changhong.factory/factorydata"),
					vals, null, null);
		} catch (SQLException e) {
			Log.v("factory", "update " + name + " Exception!");
		}
		if (ret == -1) {
			Log.v("factory", "update " + name + " failed!");
		}

	}

	public boolean isCurrentTvSystemIsIsdb() {
		/*
		 * //zcj 2018-10-31 Log.d("factory", "changhong.tvsystem:" +
		 * SystemProperties.getInt("changhong.tvsystem", 1) + "");
		 */
		// zcj 2018-10-30 return SystemProperties.getInt("changhong.tvsystem",
		// 1) == TvCommonManager.TV_SYSTEM_ISDB;
		return false;
	}

	public int updateCIPlusKey() {
		return Page2.updateCIPlusKey();
	}

	public boolean changeBootLogoByPath(String path){
		return Page2.changeBootLogoByPath(path);
	}
	/**
	 * 
	 * @value 1 xml 0 no xml
	 */
	public int dumpChannelList(int value) {
		return Page3.dumpChannelList(value);
	}

	/**
	 * 
	 * @value 1 xml 0 no xml
	 */
	public int loadChannelList(int value) {
		return Page3.loadChannelList(value);
	}
	public int selectfirstChannel() {
		return Page3.selectfirstChannel();
	}
	public int dumpFactoryChannelListByPath(int value,String path) {
		return Page3.dumpFactoryChannelListByPath(value,path);
	}
	public int loadFactoryChannelListByPath(int value,String path) {
		return Page3.loadFactoryChannelListByPath(value,path);
	}

	public boolean deleteFileByPath(String path) {
		return Page2.deleteFileByPath(path);
	}
	public boolean deleteDirByPath(String path) {
		return Page2.deleteDirByPath(path);
	}

	public boolean setMACAddr(String src) {
		if (checkFileFormat(src)) {
			String macStr = "";
			FileInputStream inputStream = null;
			try {
				inputStream = new FileInputStream(src);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			try {
				int length = inputStream.available();
				byte[] buffer = new byte[length];
				inputStream.read(buffer);
				StringBuilder stringBuilder = new StringBuilder("");
				for (int i = 0; i < length; i++) {
					int bt = buffer[i] & 0xff;
					String str = Integer.toHexString(bt);
					if (str.length() < 2) {
						stringBuilder.append("0");
						Log.d("zcj","str.lenght===="+str.length());
					}
					stringBuilder.append(str);
					if (i < length - 1) {
						stringBuilder.append(":");
					}
				}
				macStr = stringBuilder.toString();
				Log.d("zcj","macStr======="+macStr);
				inputStream.close();
			} catch (IOException e1) {

				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			macStr = macStr.trim().replaceAll(" ", "");
			File usbMAC = getFile(src);
			// save upgrade file name
			Page2.saveUpgradeKeyFileName("MAC", usbMAC.getName());
			// remove file
			boolean remvRt = deleteFileByPath(src);
			if (!remvRt && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_MAC)) {
				Page2.setMacToIni("NG:remove USB file " + remvRt);
				return false;
			}

			if (macStr.length() == 17) {
				macStr = macStr.substring(0, 17);
				if (checkMacIsValid(macStr)) {
					boolean setMacRt = setMAC(macStr);
					if (!setMacRt && Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_MAC)) {
						Page2.setMacToIni("NG:set Mac " + setMacRt);
						return false;
					}
					// macAdress.updateValue(macStr);
					Log.v("tv", "macStr==" + macStr);
					return true;
				} else {
					if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_MAC)) {
						Page2.setMacToIni("NG:mac is not valid");
					}
					return false;
					}
			} else {
				Log.v("tv", "macStr==" + macStr);
				if (Page2.isKeyStatusIniFileExist(Contants.KEYSTATUS_MAC)) {
					Page2.setMacToIni("NG:mac length not equal 17");
				}
				return false;
			}
		} else {
			return false;
		}
	}

	public boolean setDeviceIDByPath(String src) {
		if (checkFileFormat(src)) {
			String deviceIdStr = "";
			FileInputStream inputStream = null;
			try {
				inputStream = new FileInputStream(src);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			try {
				int length = inputStream.available();
				byte[] buffer = new byte[length];
				inputStream.read(buffer);
				StringBuilder stringBuilder = new StringBuilder("");
				stringBuilder.append(new String(buffer));
				deviceIdStr = stringBuilder.toString();
				inputStream.close();
			} catch (IOException e1) {

				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			deviceIdStr = deviceIdStr.trim().replaceAll(" ", "");
			Log.v("tv", "deviceIdStr==" + deviceIdStr);
			return setDeviceID(deviceIdStr);
		} else {
			return false;
		}
	}

	//check the file is ok
	private boolean checkFileFormat(String path) {
		boolean real=new File(path).length()>0;
		return (path.endsWith(".bin") || path.endsWith(".BIN"))&&real;
	}
	private boolean checkFileFormatCIkey(String path) {
		boolean real=new File(path).length()>0;
		return (path.endsWith(".KEY") || path.endsWith(".key"))&&real;
	}

	// check key file MD5
	public String getMD5(String filePath, int fileLenght) {
		ArrayList<Byte> keyFileCode = new ArrayList<Byte>();
		keyFileCode = MtkTvFApiSystem.getInstance().readFileByte(filePath, fileLenght, 0);

		byte[] byteKey = new byte[keyFileCode.size()];
		String str = keyFileCode.toString();
		for (int i = 0; i < keyFileCode.size(); i++) {
			byteKey[i] = keyFileCode.get(i).byteValue();
		}

		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(byteKey);
			byte[] encryption = md5.digest();

			StringBuffer strBuf = new StringBuffer();
			for (int i = 0; i < encryption.length; i++) {
				if (Integer.toHexString(0xff & encryption[i]).length() == 1) {
					strBuf.append("0").append(Integer.toHexString(0xff & encryption[i]));
				} else {
					strBuf.append(Integer.toHexString(0xff & encryption[i]));
				}
			}

			return strBuf.toString();
		} catch (NoSuchAlgorithmException e) {
			return "";
		}
	}

	public boolean checkMacIsValid(String macStr) {
		if (macStr == null || macStr.equals("")) {
			return false;
		}
		String macRegex0 = "([Ff0]{2}[-,:]){5}[Ff0]{2}";
		String macRegex = "([A-Fa-f0-9]{2}[-,:]){5}[A-Fa-f0-9]{2}";
		if (macStr.matches(macRegex0)) {
			return false;
		} else if (macStr.matches(macRegex)) {
			return true;
		}
		return false;
	}
	public boolean checkDeviceIdIsValid(String deviceStr){
		if (deviceStr == null || deviceStr.equals("")) {
			return false;
		}
		String deviceRegex="[Ff0]{19,}";
		if(deviceStr.matches(deviceRegex)){
			return false;
		}else{
			return true;
		}
	}

	public boolean taKeyReload(String keyName) {
		MtkTvFApiSystem mMtkTvFApiSystem=MtkTvFApiSystem.getInstance();
		switch (keyName.toUpperCase()) {
		case "PLAYREADY": {
			String keyStatus1 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY_1);
			String keyStatus2 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY_2);
			if (keyStatus1.contains("encrypt")) {
				int encryptRt1 = -1;
				for (int i = 0; i < 2; i++) {
					encryptRt1 = mMtkTvFApiSystem.encryptSystemKey(
							MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_PLAYREADY30, true);
					if (encryptRt1 == 0) {
						Page2.setPlayReadyKey_1ToIni("OK");
						break;
					}
				}

			} else if (keyStatus2.contains("encrypt")) {
				int encryptRt2 = -1;
				for (int i = 0; i < 2; i++) {
					encryptRt2 = mMtkTvFApiSystem.encryptSystemKey(
							MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_PLAYREADYPUB30, false);
					if (encryptRt2 == 0) {
						Page2.setPlayReadyKey_2ToIni("OK");
						break;
					}
				}
			}
			keyStatus1 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY_1);
			keyStatus2 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY_2);
			if (keyStatus1.equalsIgnoreCase("OK") && keyStatus2.equalsIgnoreCase("OK")) {
				Page2.setPlayReadyKeyToIni("OK");
				return true;
			} else {
				return false;
			}
		}
		/*
		case "PLAYREADY25": {
			String keyStatus1 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY25_1);
			String keyStatus2 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY25_2);
			if (keyStatus1.contains("encrypt")) {
				int encryptRt1 = -1;
				for (int i = 0; i < 2; i++) {
					encryptRt1 = mMtkTvFApiSystem.encryptSystemKey(
							MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_PLAYREADY25, true);
					if (encryptRt1 == 0) {
						Page2.setPlayReadyKey25_1ToIni("OK");
						break;
					}
				}

			} else if (keyStatus2.contains("encrypt")) {
				int encryptRt2 = -1;
				for (int i = 0; i < 2; i++) {
					encryptRt2 = mMtkTvFApiSystem.encryptSystemKey(
							MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_PLAYREADYPUB25, false);
					if (encryptRt2 == 0) {
						Page2.setPlayReadyKey25_2ToIni("OK");
						break;
					}
				}
			}
			keyStatus1 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY25_1);
			keyStatus2 = MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					Contants.KEYSTATUS_PLAYREADY25_2);
			if (keyStatus1.equalsIgnoreCase("OK") && keyStatus2.equalsIgnoreCase("OK")) {
				Page2.setPlayReadyKey25ToIni("OK");
				return true;
			} else {
				return false;
			}
		}
		*/
		case "HDCP1X": {
			int encryptRt = -1;
			for (int i = 0; i < 2; i++) {
				encryptRt = Page2.reloadNeedKeys();
				if (encryptRt == 0) {
					Page2.setHdcpKey1xToIni("OK");
					break;
				}
			}
			return encryptRt == 0 ? true : false;
			
		}
		case "HDCP2X": {
			int encryptRt = -1;
			for (int i = 0; i < 2; i++) {
				encryptRt = Page2.reloadNeedKeys();
				if (encryptRt == 0) {
					Page2.setHdcpKey2xToIni("OK");
					break;
				}
			}
			return encryptRt == 0 ? true : false;
		}
		case "WIDEVINE": {
			int encryptRt = -1;
			for (int i = 0; i < 2; i++) {
				encryptRt = mMtkTvFApiSystem
						.encryptSystemKey(MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_WVCENC, true);
				if (encryptRt == 0) {
					Page2.setWidevineKeyToIni("OK");
					break;
				}

			}
			return encryptRt == 0 ? true : false;
		}
		case "KEYMASTER": {
			int encryptRt = -1;
			for (int i = 0; i < 2; i++) {
				encryptRt = mMtkTvFApiSystem
						.encryptSystemKey(MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_KEYMASTER, true);
				if (encryptRt == 0) {
					Page2.setKeyMasterToIni("OK");
					break;
				}
			}
			return encryptRt == 0 ? true : false;

		}
		case "NETFLIX": {
			int encryptRt = -1;
			for (int i = 0; i < 2; i++) {
				encryptRt = mMtkTvFApiSystem
						.encryptSystemKey(MtkTvFApiKeyManager.EnumSystemKeyType.E_MTK_FAPI_SYSTEM_KEY_NETFLIX50, true);
				if (encryptRt == 0) {
					break;
				}
			}
			return encryptRt == 0 ? true : false;
		}
		default:
			return false;
		}
	}

	public static boolean isFactoryShowNoFunc() {		
	    if(showNoFunc == null){
	        showNoFunc=getFactoryShowNoFunc();
	    }
	    if(showNoFunc.equalsIgnoreCase("1") ? true : false){
	        return true;
	    }else{
	    	return false;
	    }    
	}

	public static void setFactoryShowNoFunc(int showNoFunc) {
	    FactorySetting.showNoFunc = showNoFunc+"";
	    MtkTvFApiInformation.getInstance().setIniParameter(
	        Contants.PATH_FACTORYINI, Contants.FACTORY_SHOW_NO_FUNC, "" + showNoFunc);
	}

	public static String getFactoryShowNoFunc() {
	    String showNoFunc = MtkTvFApiInformation.getInstance().getIniParameter(
	        Contants.PATH_FACTORYINI, Contants.FACTORY_SHOW_NO_FUNC);
	    return showNoFunc;

	}

	public static boolean isDataIndexExistVersion(){
		if(Contants.FACTORY_DATAINDEX_DATAVERSION==""||Contants.FACTORY_DATAINDEX_DATAVERSION.length()==0){
			return false;
		}else{
			return true;
		}
	}

	public void initDataPath(String dataIndexPath){
		Log.d("zcj","Start initDataPath");
		Map<String, Object> mDataIndex = FactoryIniReadService.readIni(dataIndexPath);
//        for(String key:mDataIndex.keySet()){
//            Map<String,String> data =(Map<String, String>)mDataIndex.get(key);
//            Log.d("zcj",key);
//            for(String k:data.keySet()){
//                Log.d("zcj",data.get(k));
//            }
//        }
		if(mDataIndex==null || mDataIndex.size()==0){
			Log.d("CHFactory.factorySetting","mDataIndex is null,Path="+dataIndexPath);
		}else {
			Contants.PATH_FACTORYINI = ((Map<String, String>) mDataIndex.get("Factory")).get("m_pFactoryRecord_File");
			Contants.PATH_CUSTOM_FUNC_INI = ((Map<String, String>) mDataIndex.get("Misc")).get("m_pCustomizationFunc_File");
			Contants.PATH_PROJECT_INFO = ((Map<String, String>) mDataIndex.get("model")).get("m_pModeInfo_File");
			Contants.PATH_INPUT_SOURCE = ((Map<String, String>) mDataIndex.get("InputSource")).get("m_pInputSourceConfig_File");
			Contants.PATH_IR_CONFIG = ((Map<String, String>) mDataIndex.get("ir")).get("m_pIrConfig_File");
			Contants.FACTORY_PAGE2_PQ_PATH = ((Map<String, String>) mDataIndex.get("panel")).get("PQBinPathName");
			String FACTORY_PAGE2_PQGENERAL_COLOR = ((Map<String, String>) mDataIndex.get("PQ_general")).get("m_pIniColorTuner_File");
			Contants.FACTORY_PAGE2_PQGENERAL_PATH = FACTORY_PAGE2_PQGENERAL_COLOR.substring(0, FACTORY_PAGE2_PQGENERAL_COLOR.lastIndexOf("/") + 1);
			Contants.FACTORY_PAGE2_AQ_PATH = ((Map<String, String>) mDataIndex.get("AQ")).get("AQPathName");
			Contants.FACTORY_PAGE2_COLORMA_PATH = ((Map<String, String>) mDataIndex.get("ColorMatrix")).get("MatrixName");
			Contants.FACTORY_PAGE2_COLORMA_PATH = Contants.FACTORY_PAGE2_COLORMA_PATH.substring(0,Contants.FACTORY_PAGE2_COLORMA_PATH.lastIndexOf("/")+1);
			Contants.FACTORY_PAGE2_PANEL_INI_PATH = ((Map<String, String>) mDataIndex.get("panel")).get("m_pPanelName");
			Contants.FACTORY_PAGE2_PANEL_PATH = Contants.FACTORY_PAGE2_PANEL_INI_PATH.substring(0, Contants.FACTORY_PAGE2_PANEL_INI_PATH.lastIndexOf("/") + 1);
			String FACTORY_PAGE2_MODEL_PATH_CUSTOMER1INI=((Map<String, String>) mDataIndex.get("model")).get("m_customerIniFile");
			Contants.FACTORY_PAGE2_MODEL_PATH = FACTORY_PAGE2_MODEL_PATH_CUSTOMER1INI.substring(0,FACTORY_PAGE2_MODEL_PATH_CUSTOMER1INI.lastIndexOf("/")+1);
			Contants.FACTORY_PAGE2_EDIDBIN_PATH = ((Map<String, String>) mDataIndex.get("EDID")).get("m_pEdidBinPath");
			Contants.FACTORY_PAGE2_HDRBIN_INI_PATH = ((Map<String, String>) mDataIndex.get("Hdr")).get("m_pIniFile");
			Contants.FACTORY_PAGE2_HDRBIN_PATH = Contants.FACTORY_PAGE2_HDRBIN_INI_PATH.substring(0, Contants.FACTORY_PAGE2_HDRBIN_INI_PATH.lastIndexOf("/")+1);
			Contants.FACTORY_PAGE2_MODULE_NAME_PATH = ((Map<String, String>) mDataIndex.get("module")).get("m_pModuleName");
			Contants.FACTORY_PAGE2_MODULE_PATH = Contants.FACTORY_PAGE2_MODULE_NAME_PATH.substring(0, Contants.FACTORY_PAGE2_MODULE_NAME_PATH.lastIndexOf("/") + 1);
			Contants.FACTORY_PAGE2_CUSTOMER_PATH = ((Map<String, String>) mDataIndex.get("model")).get("m_customerIniFile");
			Contants.FACTORY_PAGE1_AQ_VERSION_PATH = Contants.FACTORY_PAGE2_AQ_PATH + "AQ_Version.ini";
			Contants.FACTORY_EXTRA_BOARD_PATH = ((Map<String, String>) mDataIndex.get("board")).get("m_pBoardName");
			if(mDataIndex.containsKey("CustomerDataVersion")) {
				Contants.FACTORY_DATAINDEX_DATAVERSION = ((Map<String, String>) mDataIndex.get("CustomerDataVersion")).get("m_DataVersion");
			}
			if(((Map<String,String>) mDataIndex.get("panel")).containsKey("HSYPQBinPathName")) {
				Contants.FACTORY_PAGE1_HSYPQBIN_PATH = ((Map<String, String>) mDataIndex.get("panel")).get("HSYPQBinPathName");
			}
			Contants.FACTORY_BOOTLOGOCFG_FILE=((Map<String, String>) mDataIndex.get("BootLogoMusic")).get("m_pBootLogoMusicCfg_File");
			if(((Map<String,String>) mDataIndex.get("TCON_BIN")).containsKey("m_pIniTconCfgFile")) {
				Contants.FACTORY_TCONCFGFILE = ((Map<String, String>) mDataIndex.get("TCON_BIN")).get("m_pIniTconCfgFile");
			}
			try {
				Contants.FACTORY_DATAINDEX_HASHKEY_SELECT = ((Map<String, String>) mDataIndex.get("CustomerDataVersion")).get("m_hashkeySelect");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public String getPQIniVersion(){
		return Page1.getPQIniVersion();
	}
	public boolean isColRegion(){ return Page1.isColRegion();}

	public ArrayList<String> getProjectIdTotalList(){
		return Page1.getProjectIdTotalList();
	}
	public String getTconBinVersion() {
		return Page1.getTconBinVer();
	}
	public int getTconEnable(){
		return Page1.getTconEnable();
	}
	public int setTconEnable(int enable){
		return Page1.setTconEnable(enable);
	}

}
